home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 1 / CU Amiga Magazine CD-ROM Special Edition (1995)(EMAP Images)(GB)[Issue 1995-11].iso / Aminet / comm / tcp / ATCP_sdk_40_gc.lha / AmiTCP-4.0-gcc / netinclude / rpc / svc.h < prev    next >
C/C++ Source or Header  |  1995-04-07  |  8KB  |  250 lines

  1. #ifndef RPC_SVC_H
  2. #define RPC_SVC_H
  3. /*
  4.  * $Id: svc.h,v 4.1 1994/09/26 08:09:11 jraja Exp jraja $
  5.  *
  6.  * Server-side remote procedure call interface.
  7.  *
  8.  * Copyright © 1994 AmiTCP/IP Group,
  9.  *                  Network Solutions Development Inc.
  10.  *                  All rights reserved.
  11.  *
  12.  */
  13. /* @(#)svc.h    2.2 88/07/29 4.0 RPCSRC; from 1.20 88/02/08 SMI */
  14.  
  15. /*
  16.  * Copyright (C) 1984, Sun Microsystems, Inc.
  17.  */
  18.  
  19. /*
  20.  * This interface must manage two items concerning remote procedure calling:
  21.  *
  22.  * 1) An arbitrary number of transport connections upon which rpc requests
  23.  * are received.  The two most notable transports are TCP and UDP;  they are
  24.  * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
  25.  * they in turn call xprt_register and xprt_unregister.
  26.  *
  27.  * 2) An arbitrary number of locally registered services.  Services are
  28.  * described by the following four data: program number, version number,
  29.  * "service dispatch" function, a transport handle, and a boolean that
  30.  * indicates whether or not the exported program should be registered with a
  31.  * local binder service;  if true the program's number and version and the
  32.  * port number from the transport handle are registered with the binder.
  33.  * These data are registered with the rpc svc system via svc_register.
  34.  *
  35.  * A service's dispatch function is called whenever an rpc request comes in
  36.  * on a transport.  The request's program and version numbers must match
  37.  * those of the registered service.  The dispatch function is passed two
  38.  * parameters, struct svc_req * and SVCXPRT *, defined below.
  39.  */
  40.  
  41. enum xprt_stat {
  42.     XPRT_DIED,
  43.     XPRT_MOREREQS,
  44.     XPRT_IDLE
  45. };
  46.  
  47. /*
  48.  * Server side transport handle
  49.  */
  50. typedef struct SVCXPRT {
  51.     int        xp_sock;
  52.     u_short        xp_port;     /* associated port number */
  53.     struct xp_ops {
  54.         bool_t    (*xp_recv)(struct SVCXPRT *xprt, struct rpc_msg *msg);     /* receive incomming requests */
  55.         enum xprt_stat (*xp_stat)(struct SVCXPRT *xprt); /* get transport status */
  56.         bool_t    (*xp_getargs)(struct SVCXPRT *xprt, xdrproc_t xargs,
  57.                       void * argsp); /* get arguments */
  58.         bool_t    (*xp_reply)(struct SVCXPRT *xprt,
  59.                     struct rpc_msg *msg);  /* send reply */
  60.         bool_t    (*xp_freeargs)(struct SVCXPRT *xprt, xdrproc_t xargs, 
  61.                       void * argsp);/* free mem allocated for args */
  62.         void    (*xp_destroy)(struct SVCXPRT *xprt); /* destroy this struct */
  63.     } *xp_ops;
  64.     long        xp_addrlen;     /* length of remote address */
  65.     struct sockaddr_in xp_raddr;     /* remote address */
  66.     struct opaque_auth xp_verf;     /* raw response verifier */
  67.     caddr_t        xp_p1;         /* private */
  68.     caddr_t        xp_p2;         /* private */
  69. } SVCXPRT;
  70.  
  71. /*
  72.  *  Approved way of getting address of caller
  73.  */
  74. #define svc_getcaller(x) (&(x)->xp_raddr)
  75.  
  76. /*
  77.  * Operations defined on an SVCXPRT handle
  78.  *
  79.  * SVCXPRT        *xprt;
  80.  * struct rpc_msg    *msg;
  81.  * xdrproc_t         xargs;
  82.  * caddr_t         argsp;
  83.  */
  84. #define SVC_RECV(xprt, msg)                \
  85.     (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
  86. #define svc_recv(xprt, msg)                \
  87.     (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
  88.  
  89. #define SVC_STAT(xprt)                    \
  90.     (*(xprt)->xp_ops->xp_stat)(xprt)
  91. #define svc_stat(xprt)                    \
  92.     (*(xprt)->xp_ops->xp_stat)(xprt)
  93.  
  94. #define SVC_GETARGS(xprt, xargs, argsp)            \
  95.     (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
  96. #define svc_getargs(xprt, xargs, argsp)            \
  97.     (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
  98.  
  99. #define SVC_REPLY(xprt, msg)                \
  100.     (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
  101. #define svc_reply(xprt, msg)                \
  102.     (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
  103.  
  104. #define SVC_FREEARGS(xprt, xargs, argsp)        \
  105.     (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
  106. #define svc_freeargs(xprt, xargs, argsp)        \
  107.     (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
  108.  
  109. #define SVC_DESTROY(xprt)                \
  110.     (*(xprt)->xp_ops->xp_destroy)(xprt)
  111. #define svc_destroy(xprt)                \
  112.     (*(xprt)->xp_ops->xp_destroy)(xprt)
  113.  
  114.  
  115. /*
  116.  * Service request
  117.  */
  118. struct svc_req {
  119.     u_long        rq_prog;    /* service program number */
  120.     u_long        rq_vers;    /* service protocol version */
  121.     u_long        rq_proc;    /* the desired procedure */
  122.     struct opaque_auth rq_cred;    /* raw creds from the wire */
  123.     caddr_t        rq_clntcred;    /* read only cooked cred */
  124.     SVCXPRT    *rq_xprt;        /* associated transport */
  125. };
  126.  
  127.  
  128. /*
  129.  * Service registration
  130.  *
  131.  *  protocol is like TCP or UDP, zero means do not register 
  132.  */
  133. extern bool_t    svc_register(SVCXPRT * xprt, u_long prog, u_long vers,
  134.                  void (* dispatch)(struct svc_req *, SVCXPRT *),
  135.                  int protocol);
  136.  
  137. /*
  138.  * Service un-registration
  139.  */
  140. extern void    svc_unregister(u_long prog, u_long vers);
  141.  
  142. /*
  143.  * Transport registration.
  144.  */
  145. extern void    xprt_register(SVCXPRT * xprt);
  146.  
  147. /*
  148.  * Transport un-register
  149.  */
  150. extern void    xprt_unregister(SVCXPRT * xprt);
  151.  
  152.  
  153.  
  154.  
  155. /*
  156.  * When the service routine is called, it must first check to see if it
  157.  * knows about the procedure;  if not, it should call svcerr_noproc
  158.  * and return.  If so, it should deserialize its arguments via 
  159.  * SVC_GETARGS (defined above).  If the deserialization does not work,
  160.  * svcerr_decode should be called followed by a return.  Successful
  161.  * decoding of the arguments should be followed the execution of the
  162.  * procedure's code and a call to svc_sendreply.
  163.  *
  164.  * Also, if the service refuses to execute the procedure due to too-
  165.  * weak authentication parameters, svcerr_weakauth should be called.
  166.  * Note: do not confuse access-control failure with weak authentication!
  167.  *
  168.  * NB: In pure implementations of rpc, the caller always waits for a reply
  169.  * msg.  This message is sent when svc_sendreply is called.  
  170.  * Therefore pure service implementations should always call
  171.  * svc_sendreply even if the function logically returns void;  use
  172.  * xdr.h - xdr_void for the xdr routine.  HOWEVER, tcp based rpc allows
  173.  * for the abuse of pure rpc via batched calling or pipelining.  In the
  174.  * case of a batched call, svc_sendreply should NOT be called since
  175.  * this would send a return message, which is what batching tries to avoid.
  176.  * It is the service/protocol writer's responsibility to know which calls are
  177.  * batched and which are not.  Warning: responding to batch calls may
  178.  * deadlock the caller and server processes!
  179.  */
  180.  
  181. extern bool_t    svc_sendreply(SVCXPRT * xprt, xdrproc_t xdr_results,
  182.                   caddr_t xdr_location);
  183. extern void    svcerr_decode(SVCXPRT * xprt);
  184. extern void    svcerr_weakauth(SVCXPRT * xprt);
  185. extern void    svcerr_noproc(SVCXPRT * xprt);
  186. extern void    svcerr_progvers(SVCXPRT * xprt, 
  187.                 u_long low_vers, u_long high_vers);
  188. extern void    svcerr_auth(SVCXPRT * xprt, enum auth_stat why);
  189. extern void    svcerr_noprog(SVCXPRT * xprt);
  190. extern void    svcerr_systemerr(SVCXPRT * xprt);
  191.     
  192. /*
  193.  * Lowest level dispatching -OR- who owns this process anyway.
  194.  * Somebody has to wait for incoming requests and then call the correct
  195.  * service routine.  The routine svc_run does infinite waiting; i.e.,
  196.  * svc_run never returns.
  197.  * Since another (co-existant) package may wish to selectively wait for
  198.  * incoming calls or other events outside of the rpc architecture, the
  199.  * routine svc_getreq is provided.  It must be passed readfds, the
  200.  * "in-place" results of a select system call (see select, section 2).
  201.  */
  202.  
  203. /*
  204.  * Global keeper of rpc service descriptors in use
  205.  * dynamic; must be inspected before each call to select 
  206.  */
  207. #ifdef FD_SETSIZE
  208. extern fd_set svc_fdset;
  209. #define svc_fds svc_fdset.fds_bits[0]    /* compatibility */
  210. #else
  211. extern int svc_fds;
  212. #endif /* def FD_SETSIZE */
  213.  
  214. /*
  215.  * a small program implemented by the svc_rpc implementation itself;
  216.  * also see clnt.h for protocol numbers.
  217.  */
  218. extern void rpctest_service();
  219.  
  220. extern void    svc_getreq(int rdfds);
  221. extern void    svc_getreqset(fd_set * readfds); /* takes fdset instead of int */
  222. extern void    svc_run(void);      /* never returns */
  223.  
  224. /*
  225.  * Socket to use on svcxxx_create call to get default socket
  226.  */
  227. #define    RPC_ANYSOCK    -1
  228.  
  229. /*
  230.  * These are the existing service side transport implementations
  231.  */
  232.  
  233. /*
  234.  * Memory based rpc for testing and timing.
  235.  */
  236. extern SVCXPRT *svcraw_create(void);
  237.  
  238. /*
  239.  * Udp based rpc.
  240.  */
  241. extern SVCXPRT *svcudp_create(int sock);
  242. extern SVCXPRT *svcudp_bufcreate(int sock, u_int sendsz, u_int recvsz);
  243.  
  244. /*
  245.  * Tcp based rpc.
  246.  */
  247. extern SVCXPRT *svctcp_create(int sock, u_int sendsize, u_int recvsize);
  248.  
  249. #endif /* !RPC_SVC_H */
  250.